//
//  WebViewController.swift
//  BaseSwift
//
//  Created by ghwang on 2019/7/25.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit
import WebKit

class WebViewController: UIViewController {

    let webView = WKWebView()
    var url:String = ""
    var myTitle:String = ""
    var isWord = false
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.backgroundColor
        self.navigationView.setTitle(myTitle)
        self.view.addSubview(webView)
        let _ = webView.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: HT_StatusBarAndNavigationBarHeight, left: 0, bottom: 0, right: 0))
        webView.isOpaque = false
        webView.uiDelegate = self
        webView.navigationDelegate = self
        webView.backgroundColor = UIColor.white
        if self.isWord == true {
            
            webView.load(URLRequest(url: URL(fileURLWithPath:self.url)))

            
        }else{
            
            webView.load(URLRequest(url: URL(string: self.url)!))

        }
        
    }
    

}

extension WebViewController:WKUIDelegate,WKNavigationDelegate{
    
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
     
        SVProgressHUD.show()
        SVProgressHUD.setDefaultStyle(.dark)
        SVProgressHUD.setDefaultAnimationType(.flat)
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        
        SVProgressHUD.dismiss(withDelay: 0)

    }
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
        
        SVProgressHUD.dismiss(withDelay: 0)
        ToastUtil.showHUDError(msg: "加载失败")
    }



}
